package megrez.common.core.bean;

import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.Map;

import lombok.Data;
import megrez.common.core.util.CommonRuntimeException;

/**
 * Minio用户元数据
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@Data
public class MinioUserMetadata {
    public static final String FIELD_OBJECT_ID = "objectid";
    public static final String FIELD_BUCKET = "bucket";
    public static final String FIELD_MINIO_ID = "minioid";
    public static final String FIELD_FILE_NAME = "filename";
    public static final String FIELD_FILE_SIZE = "filesize";
    public static final String FIELD_CREATED_BY = "createdby";
    public static final String FIELD_CREATED_ON = "createdon";
    public static final String FIELD_CONTENT_TYPE = "contenttype";

    private String objectid;
    private String bucket;
    private String minioid;
    private String filename;
    private long filesize;
    private String createdby;
    private ZonedDateTime createdon;
    private String contenttype;

    public Map<String, String> toMap() {
        if (objectid == null || bucket == null || minioid == null || filename == null || createdby == null || createdon == null || contenttype == null) {
            // 校验所有的属性不能是null，否则上传文件异常
            throw new CommonRuntimeException("MinioUserMetadata instance properites must not be null: {}", this.toString());
        }
        final Map<String, String> rslt = new HashMap<>();
        rslt.put(FIELD_OBJECT_ID, this.objectid);
        rslt.put(FIELD_BUCKET, this.bucket);
        rslt.put(FIELD_MINIO_ID, this.minioid);
        rslt.put(FIELD_FILE_NAME, this.filename);
        rslt.put(FIELD_FILE_SIZE, String.valueOf(this.filesize));
        rslt.put(FIELD_CREATED_BY, this.createdby);
        rslt.put(FIELD_CREATED_ON, this.createdon.toString());
        rslt.put(FIELD_CONTENT_TYPE, this.contenttype);
        return rslt;
    }
}
